<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Keyorder extends Model
{
    protected $table = 'key_order';
    protected $primaryKey = 'id';

    public static function userKeyListOrder($users_id)
    {
        return self::select("key_order.*","minapps_lists.head_img","minapps_lists.name")->leftJoin('minapps_lists','key_order.appid', '=','minapps_lists.appid')->where("key_order.users_id",$users_id)->take(20)->get();
    }

    public static function keyListActive($key,$users_id,$status)
    {
        return self::where("key",$key)->update(["users_id"=>$users_id,"status"=>$status]);
    }

    public static function keyOrderCreate($users_id,$score,$appid,$status)
    {
        return self::insert(["users_id"=>$users_id,"score"=>$score,"appid"=>$appid,"status"=>$status,"created_at"=>time()]);
    }
}
